<template>
  <div>
    <van-pull-refresh class="dfme" :success-text="tishinr" :success-duration="2000" v-model="isLoading" @refresh="onRefresh">
    
          <van-list
          class="vanlist"
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="onLoad"
        >
          
          <Thearticlelists v-for="(item,index) in list" :data="item" :key="index"></Thearticlelists>
        </van-list>
        
      </van-pull-refresh>
    
  
  </div>
</template>
<script>
import { UserChannleList } from "../../../api/user";
import  Thearticlelists  from '../../../components/Thearticlelists/index.vue'
export default {
  name: "userChannelwenz",
  props: {
    channel: {
      type: Object,
      required: true,
    },
  },
  components:{
    Thearticlelists
  },
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      gegnxTime: null,
      isLoading:true,
      tishinr:''
    };
  },
  created() {},
  methods: {
    async onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求

      var { data } = await this.getChannel();
      // 加载状态结束
      // console.log(data.data.pre_timestamp)

      // console.log(data.data.results)
      // this.list.push(...data.data.results)
      this.list.push(...data.data.results);
      // console.log(data.data.results.length);
      this.loading = false;
      // console.log(this.list)

      // 数据全部加载完成
      if (data.data.results.length) {
        this.gegnxTime = data.data.pre_timestamp;
      } else {
        this.finished = true
      }
      // console.log(this.list)
    },
    getChannel() {
      return UserChannleList({
        channel_id: this.channel.id,
        timestamp: this.gegnxTime || Date.now(),
        with_top: 1
      })
    },
    async onRefresh(){
      var { data } = await UserChannleList({
        channel_id: this.channel.id,
        timestamp:Date.now(),
        with_top: 1
      })
      this.list.unshift(...data.data.results)
      // console.log(this)
      // console.log()
      this.tishinr = `更新了${data.data.results.length}条数据`
      this.isLoading = false

      
      
    }
  }
};
</script>
<style scoped lang="less">
/deep/.van-list {
  text-align: left;
}
/deep/.van-tabs__content {
  position: fixed;
}

.dfme {
  position: fixed;
  right: 0;
  left: 0;
  top: 90px;
  bottom: 50px;
  overflow-y: auto;
  // height: 1000px;


  
}



</style>>

